package com.example.springboot006web.controller;

import com.example.springboot006web.repository.User;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

/**
 * @description: TODO
 * @author: uu
 * @data: 2023/7/1 下午 07:11
 * @version: v1.0
 */
@RestController
public class ViewController {


    @GetMapping("/modelAndView")
    public ModelAndView hello (Model model){
        ModelAndView mv = new ModelAndView();
        mv.addObject("name", "lisi");
        mv.addObject("age","20");
        mv.addObject("hello");
        return mv;
    }
    @GetMapping("/json")
    public User returnJson(){
        User user = new User("cms","234");
        return user;
    }

    @GetMapping("/json2")
    public ResponseEntity<User> returnEntity(){
        User user = new User("name","zhangsan");
        ResponseEntity<User> userResponseEntity = new ResponseEntity<User>(user, HttpStatus.NOT_FOUND);
        return userResponseEntity;
    }
}
